package com.zpark.dao;

import com.zpark.pojo.Department;
import com.zpark.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@Repository
public class EmployeeDao {
    //模拟数据库中的数据
    private static Map<Integer, Employee> employees = null;
    @Autowired
    private DepartmentDao departmentDao;
    static{
        employees = new HashMap<Integer,Employee>();//创建一个部门表

        employees.put(101,new Employee(101,"AA","234567@qq.com",1,new Department(01,"教学部")));
        employees.put(102,new Employee(102,"BB","1234567@qq.com",0,new Department(02,"后勤部")));
        employees.put(103,new Employee(103,"CC","2345678@qq.com",1,new Department(03,"运营部")));
        employees.put(104,new Employee(104,"DD","2345679@qq.com",1,new Department(04,"教研部")));
        employees.put(105,new Employee(105,"EE","12345678@qq.com",0,new Department(5,"市场部")));
    }
    //获得所有部门信息
   private static Integer initId = 106;
    public void save(Employee employee){
        if(employee.getId()==null){
            employee.setId(initId);
        }
        employee.setDepartment(departmentDao.getDepartmentById(employee.getDepartment().getId()));
        employees.put(employee.getId(),employee);
    }
    //查询全部部门员工信息
    public Collection<Employee> getAll(){
        return employees.values();
    }
    public Employee getEmployeeById(Integer id){
        return employees.get(id);
    }
    public void delEmployeeById(Integer id){
        employees.remove(id);
    }
}
